<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!-- #include file = "../core.asp" -->
<%
	var _system = $('system');
	var _database = $('database');
	_database.path = '../database/#database.mdb';
	var _md5 = $('md5');
	
	var _action = _system.read('action');
	var _id = _system.read('id');
	
	switch (_action) {
		case 'add':
			_add();
			break;
		case 'edit':
			_edit();
			break;
		case 'save':
			_save();
			break;
		case 'delete':
			_delete();
			break;
		case 'update':
			_update();
			break;
		default:
			_main();
			break;
	}
%>

<%
	function _update() {
		var _name = _system.read('name');
		var _password = _md5.encrypt(_system.read('password'));
		
		var _sql = 'update [Manager] set [Password] = \'' + _password + '\' where [Id] = ' + _id;
		var _url = 'manager.asp';

		_database.execute(_sql);
		_system.redirect(_url);
	}
%>

<%
	function _edit() {
		_header();
		var _manager = _database.query('select [Name], [Password] from [Manager] where [Id] = ' + _id);
%>
	<tr>
    	<th colspan="2" class="border"><strong>内容管理 - 编辑管理员</strong></th>
    </tr>
    <tr>
   	  	<td valign="top">
       	  	<form action="?action=update&id=<% =_id %>" method="post">
                <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999">
                    <tr>
                        <td bgcolor="#eeeeee" height="24" width="80">&nbsp;<label for="name"><strong>名称</strong></label></td>
                        <td bgcolor="#eeeeee">&nbsp;<input type="text" name="name" id="name" size="40" value="<% =_manager[0].name %>" readonly="readonly" /></td>
                     </tr>
                    <tr>
                        <td bgcolor="#eeeeee" height="24" width="80">&nbsp;<label for="password"><strong>密码</strong></label></td>
                        <td bgcolor="#eeeeee">&nbsp;<input type="text" name="password" id="password" size="40" /></td>
                    </tr>
                    <tr>
                        <td bgcolor="#eeeeee" height="24" colspan="2"><input type="submit" name="submit" id="submit" value="提交" class="button" /></td>
                    </tr>
                </table>
           	</form>
        </td>
    </tr>
<%
		_footer();
	}
%>

<%
	function _delete() {
		var _sql = 'delete * from [Manager] where [Id] = ' + _id;
		var _url = 'manager.asp';

		_database.execute(_sql);
		_system.redirect(_url);
	}
%>


<%
	function _save() {
		var _name = _system.read('name');
		var _password = _md5.encrypt(_system.read('password'));
		
		var _sql = 'insert into [Manager]([Name], [Password]) values (\'' + _name + '\', \'' + _password + '\')';
		var _url = 'manager.asp';
		_database.execute(_sql);

		_system.redirect(_url);
	}
%>

<%
	function _add() {
		_header();
%>
	<tr>
    	<th colspan="2" class="border"><strong>内容管理 - 添加新管理员</strong></th>
    </tr>
    <tr>
   	  	<td valign="top">
       	  	<form action="?action=save" method="post">
                <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999">
                    <tr>
                        <td bgcolor="#eeeeee" height="24" width="80">&nbsp;<label for="name"><strong>名称</strong></label></td>
                        <td bgcolor="#eeeeee">&nbsp;<input type="text" name="name" id="name" size="40" /></td>
                     </tr>
                    <tr>
                        <td bgcolor="#eeeeee" height="24" width="80">&nbsp;<label for="password"><strong>密码</strong></label></td>
                        <td bgcolor="#eeeeee">&nbsp;<input type="text" name="password" id="password" size="40" /></td>
                    </tr>
                    <tr>
                        <td bgcolor="#eeeeee" height="24" colspan="2"><input type="submit" name="submit" id="submit" value="提交" class="button" /></td>
                    </tr>
                </table>
           	</form>
        </td>
    </tr>
<%
		_footer();
	}
%>


<%
	function _main() {
		_header();
		var _index = parseInt(_system.read('page')) || 1;
		var _managers = _database.query('[Id], [Name], [Ip], [Datetime]', '[Manager]', '', '[Datetime] desc', 0, _index, 20);
%>
	<tr>
    	<th colspan="2" class="border"><strong>管理员管理</strong></th>
    </tr>
    <tr>
   	  	<td valign="top">
        	<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999">
				<tr>
                    <td bgcolor="#eeeeee" height="24" colspan="3">&nbsp;<strong>管理员列表</strong></td>
                    <td bgcolor="#eeeeee" colspan="2" width="81">&nbsp;<a href="?action=add">添加记录</a></td>
				</tr>
<%
			for (var _index = 0; _index < _managers.length; _index++) {
%>
                <tr>
                    <td bgcolor="#eeeeee" height="24">&nbsp;<% =_managers[_index].name %></td>
                    <td bgcolor="#eeeeee" width="100">&nbsp;<% =_managers[_index].ip %></td>
                    <td bgcolor="#eeeeee" width="120">&nbsp;<% =_managers[_index].datetime %></td>
                    <td bgcolor="#eeeeee" width="40">&nbsp;<a href="?action=edit&id=<% =_managers[_index].id %>">编辑</a></td>
                    <td bgcolor="#eeeeee" width="40">&nbsp;<a href="?action=delete&id=<% =_managers[_index].id %>" onClick="return confirm('你确定要删除么?');">删除</a></td>
				</tr>
<%
			}
			if (_managers.length == 0) {
%>
				<tr>
					<td colspan="5" bgcolor="#F4F4F4" height="24">&nbsp;暂时没有管理员！</td>
				</tr>
<%
			}
			else {
				var _index = parseInt(_system.read('page')) || 1;
				var _queryString = _system.query;
				var _page = '';
				
				if (_queryString == '' || _queryString.indexOf('page') == 0) {
					_page = '<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + (_index - 1 > 0 ? _index - 1 : 1) + '">上一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/page=\d+/gi, '') + 'page=' + (_index + 1 < _database.pageCount ? _index + 1 : _database.pageCount) + '">下一页</a>&nbsp;&nbsp;共' + _database.pageCount + '页';
				}
				else {
					_page = '<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + (_index - 1 > 0 ? _index - 1 : 1) + '">上一页</a>&nbsp;&nbsp;<a href="?' + _queryString.replace(/&page=\d+/gi, '') + '&page=' + (_index + 1 < _database.pageCount ? _index + 1 : _database.pageCount) + '">下一页</a>&nbsp;&nbsp;共' + _database.pageCount + '页';
				}
%>
				<tr>
					<td colspan="5" bgcolor="#F4F4F4" height="24">&nbsp;<% =_page %></td>
				</tr>
<%
			}
%>
            </table>
        </td>
    </tr>
<%
		_footer();
	}
%>

<%
//********************************************************************************
%>
<%
	function _header() {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BestWeb Content System</title>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="script/validate.js"></script>
<script type="text/javascript" src="script/validate.js"></script>
<link rel="stylesheet" type="text/css" href="style/content.css" />
</head>

<body>
<table width="100%" border="0" cellspacing="5" cellpadding="0" class="content">
<%
	}
%>

<%
	function _footer() {
%>
</table>
</body>
</html>
<%
	}
%>
<%
//********************************************************************************
%>